package edu.gatech.cs2340.teamrocket.view.main;

import java.awt.*;

import javax.swing.*;

import edu.gatech.cs2340.teamrocket.control.guicontrol.MainGamePanelControl;
import edu.gatech.cs2340.teamrocket.model.Model;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
/**
 * This is the bottom panel of main game panel
 * @author Wai Chip Ngai
 *
 */
@SuppressWarnings("serial")
public class BottomPanel extends JPanel{

    private MainGamePanelControl aControl;
    private JButton menu, nextTurn, map, shop, stats;
    private ActionListener endTurnListener;

    public BottomPanel(MainGamePanelControl mainGamePanelControl){

        endTurnListener = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                aControl.nextTurn();
            }
        };

        this.aControl = mainGamePanelControl;

        setLayout(new GridLayout(1,5));
        setPreferredSize(new Dimension(1024, 80));
        setBorder(BorderFactory.createLineBorder(Color.black));
        menu = new JButton("Menu");
        menu.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                aControl.menu();
            }
        });
        nextTurn = new JButton("Continue");
        nextTurn.addActionListener(endTurnListener);
        map = new JButton("Show Map");
        map.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                aControl.map();
            }
        });
        shop = new JButton("Visit Shop");
        shop.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                aControl.shop();
            }
        });
        stats = new JButton("Stats");
        stats.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                aControl.stats();
            }
        });
        add(menu);
        add(stats);
        add(map);
        add(shop);
        add(nextTurn);

    }
    /**
     * What to do to the end turn button when the game ends.
     */
    public void endGame(){
        nextTurn.setText("Restart Game");
        nextTurn.removeActionListener(endTurnListener);
        nextTurn.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent arg0) {
            	Model.resetInstance();
                aControl.restartGame();

            }
        });
    }

    /**
     * A way to set the shop button.
     */
    public void setShop(boolean aBool){
        shop.setEnabled(aBool);
    }

}
